[1] "Sun Apr 19 11:44:13 2020 - Grafici e dati aggiornati e ricalcolati automaticamente."
Coronavirus Dashboard: il caso in Italia
Questa Dashboard vuole essere un aiuto alla popolazione Italiana di tenersi aggiornata a riguardo la pandemia mondiale data da COVID-19, causata dal virus SARS-CoV-2 ( 2019 severe acute respiratory syndrome coronavirus 2 ). Con focus sulla situazione Italiana, in confronto ai paesi Europei che ci stanno vicino, come Germania, Spagna e Francia.
La Dashboard è un estratto del lavoro di Rami Krispin consultabile qui: dashboard e delle sue modifiche apportate da Antoine Soetewey per il Belgio: Belgium Dashboard
Io ho implementato alcune modifiche necessarie per personalizzare e calcolare i dati per il nostro paese l’Italia.
Codice
Questo sito è stato sviluppato in R, un linguaggio di programmazione orientato alla statistica e il framework R Markdown. Il codice di questa Dashboard è disponibile su GitHub GitHub ed è liberamente modificabile.
Dati
I dati che vengono utilizzati da questa dashboard fanno parte del pacchetto R sul coronavirus e vengono aggiornati quotidianamente, come anche la dashboard. I dati grezzi sono prelevati dal Johns Hopkins University Center for Systems Science and Engineering (JHU CCSE) Coronavirus repository.
Sul Autore
Mi chiamo Pietro Boccaletto, sono un Biologo che si occupa di Bioinformatica nel campo degli RNA non codificanti. Sviluppo e mantengo tools e database che sono d’aiuto al avanzamento della ricerca scientifica.
Contatti
Per ogni domanda o Feedback, potete contattarmi a questo indirizzo email:
---
title: "COVID-2019 in ITALIA"
author: "Pietro Boccaletto"
output:
flexdashboard::flex_dashboard:
orientation: rows
#social: ["facebook", "twitter", "linkedin"]
source_code: embed
vertical_layout: fill
---
```{r setup, include=FALSE}
#------------------ Packages ------------------
library(flexdashboard)
# install.packages("devtools")
# devtools::install_github("RamiKrispin/coronavirus", force = TRUE)
library(coronavirus)
data(coronavirus)
update_datasets()
#View(coronavirus)
#max(coronavirus$date)
`%>%` <- magrittr::`%>%`
#------------------ Parameters ------------------
# Set colors
# https://www.w3.org/TR/css-color-3/#svg-color
confirmed_color <- "orange"
active_color <- "blue"
recovered_color <- "forestgreen"
death_color <- "red"
#------------------ Data ------------------
df <- coronavirus %>%
dplyr::filter(date >= "2020-01-31") %>%
dplyr::filter(Country.Region == "Italy") %>%
dplyr::group_by(Country.Region, type) %>%
dplyr::summarise(total = sum(cases)) %>%
tidyr::pivot_wider(
names_from = type,
values_from = total
) %>%
# dplyr::mutate(unrecovered = confirmed - ifelse(is.na(recovered), 0, recovered) - ifelse(is.na(death), 0, death)) %>%
dplyr::mutate(unrecovered = confirmed - ifelse(is.na(death), 0, death)) %>%
dplyr::arrange(-confirmed) %>%
dplyr::ungroup() %>%
dplyr::mutate(country = dplyr::if_else(Country.Region == "United Arab Emirates", "UAE", Country.Region)) %>%
dplyr::mutate(country = dplyr::if_else(country == "Mainland China", "China", country)) %>%
dplyr::mutate(country = dplyr::if_else(country == "North Macedonia", "N.Macedonia", country)) %>%
dplyr::mutate(country = trimws(country)) %>%
dplyr::mutate(country = factor(country, levels = country))
df_daily <- coronavirus %>%
dplyr::filter(date >= "2020-01-31") %>%
dplyr::filter(Country.Region == "Italy") %>%
dplyr::group_by(date, type) %>%
dplyr::summarise(total = sum(cases, na.rm = TRUE)) %>%
tidyr::pivot_wider(
names_from = type,
values_from = total
) %>%
dplyr::arrange(date) %>%
dplyr::ungroup() %>%
#dplyr::mutate(active = confirmed - death - recovered) %>%
dplyr::mutate(active = confirmed - death) %>%
dplyr::mutate(
confirmed_cum = cumsum(confirmed),
death_cum = cumsum(death),
recovered_cum = cumsum(recovered),
active_cum = cumsum(active)
)
df1 <- coronavirus %>% dplyr::filter(date == max(date))
```
Sommario
=======================================================================
Row {data-width=400}
-----------------------------------------------------------------------
### confirmed {.value-box}
```{r}
valueBox(
value = paste(format(sum(df$confirmed), big.mark = ","), "", sep = " "),
caption = "Casi Totali Confermati",
icon = "fas fa-user-md",
color = confirmed_color
)
```
### death {.value-box}
```{r}
valueBox(
value = paste(format(sum(df$death, na.rm = TRUE), big.mark = ","), " (",
round(100 * sum(df$death, na.rm = TRUE) / sum(df$confirmed), 1),
"%)",
sep = ""
),
caption = "Casi di morte (% di mortalità)",
icon = "fas fa-feather",
color = death_color
)
```
### recovered {.value-box}
```{r}
valueBox(
value = paste(format(sum(df$recovered, na.rm = TRUE), big.mark = ","), " (",
round(100 * sum(df$recovered, na.rm = TRUE) / sum(df$confirmed), 1),
"%)",
sep = ""
),
caption = "Guariti (% guariti)",
icon = "fas fa-heart",
color = recovered_color
)
```
Row
-----------------------------------------------------------------------
### **Casi cumulativi giornalieri per tipo** (Italia)
```{r}
plotly::plot_ly(data = df_daily) %>%
plotly::add_trace(
x = ~date,
# y = ~active_cum,
y = ~confirmed_cum,
type = "scatter",
mode = "lines+markers",
# name = "Active",
name = "Confermati",
line = list(color = confirmed_color),
marker = list(color = confirmed_color)
) %>%
plotly::add_trace(
x = ~date,
y = ~death_cum,
type = "scatter",
mode = "lines+markers",
name = "Morti",
line = list(color = death_color),
marker = list(color = death_color)
) %>%
plotly::add_trace(
x = ~date,
y = ~recovered_cum,
type = "scatter",
mode = "lines+markers",
name = "Guariti",
line = list(color = recovered_color),
marker = list(color = recovered_color)
) %>%
plotly::add_annotations(
x = as.Date("2020-01-31"),
y = 1,
text = paste("Primo Caso"),
xref = "x",
yref = "y",
arrowhead = 5,
arrowhead = 3,
arrowsize = 1,
showarrow = TRUE,
ax = -10,
ay = -90
) %>%
plotly::add_annotations(
x = as.Date("2020-02-22"),
y = 3,
text = paste("Prima Morte"),
xref = "x",
yref = "y",
arrowhead = 5,
arrowhead = 3,
arrowsize = 1,
showarrow = TRUE,
ax = -90,
ay = -90
) %>%
plotly::add_annotations(
x = as.Date("2020-03-9"),
y = 14,
text = paste(
"Misure di contenimento",
"
",
"estese a tutta l'Italia"
),
xref = "x",
yref = "y",
arrowhead = 5,
arrowhead = 3,
arrowsize = 1,
showarrow = TRUE,
ax = -10,
ay = -110
) %>%
plotly::layout(
title = "",
yaxis = list(title = "Numero cumulativo dei casi"),
xaxis = list(title = "Data"),
legend = list(x = 0.1, y = 0.9),
hovermode = "compare"
)
```
in Europa
=======================================================================
Column {data-width=400}
-------------------------------------
### **Nuovi casi confermati giornalmente**
```{r}
daily_confirmed <- coronavirus %>%
dplyr::filter(type == "confirmed") %>%
dplyr::filter(date >= "2020-02-29") %>%
dplyr::mutate(country = Country.Region) %>%
dplyr::group_by(date, country) %>%
dplyr::summarise(total = sum(cases)) %>%
dplyr::ungroup() %>%
tidyr::pivot_wider(names_from = country, values_from = total)
#----------------------------------------
# Plotting the data
daily_confirmed %>%
plotly::plot_ly() %>%
plotly::add_trace(
x = ~date,
y = ~Italy,
type = "scatter",
mode = "lines+markers",
name = "Italia"
) %>%
plotly::add_trace(
x = ~date,
y = ~Germany,
type = "scatter",
mode = "lines+markers",
name = "Germania"
) %>%
plotly::add_trace(
x = ~date,
y = ~Spain,
type = "scatter",
mode = "lines+markers",
name = "Spain"
) %>%
plotly::add_trace(
x = ~date,
y = ~France,
type = "scatter",
mode = "lines+markers",
name = "Francia"
) %>%
plotly::layout(
title = "",
legend = list(x = 0.1, y = 0.9),
yaxis = list(title = "Numbero di nuovi casi confermati"),
xaxis = list(title = "Data"),
# paper_bgcolor = "black",
# plot_bgcolor = "black",
# font = list(color = 'white'),
hovermode = "compare",
margin = list(
# l = 60,
# r = 40,
b = 10,
t = 10,
pad = 2
)
)
```
### **Distribuzione dei casi per tipo**
```{r daily_summary}
df_EU <- coronavirus %>%
# dplyr::filter(date == max(date)) %>%
dplyr::filter(Country.Region == "Italy" |
Country.Region == "France" |
Country.Region == "Germany"|
Country.Region == "Spain") %>%
dplyr::group_by(Country.Region, type) %>%
dplyr::summarise(total = sum(cases)) %>%
tidyr::pivot_wider(
names_from = type,
values_from = total
) %>%
# dplyr::mutate(unrecovered = confirmed - ifelse(is.na(recovered), 0, recovered) - ifelse(is.na(death), 0, death)) %>%
dplyr::mutate(unrecovered = confirmed - ifelse(is.na(death), 0, death)) %>%
dplyr::arrange(confirmed) %>%
dplyr::ungroup() %>%
dplyr::mutate(country = dplyr::if_else(Country.Region == "United Arab Emirates", "UAE", Country.Region)) %>%
dplyr::mutate(country = dplyr::if_else(country == "Mainland China", "China", country)) %>%
dplyr::mutate(country = dplyr::if_else(country == "North Macedonia", "N.Macedonia", country)) %>%
dplyr::mutate(country = trimws(country)) %>%
dplyr::mutate(country = factor(country, levels = country))
plotly::plot_ly(
data = df_EU,
x = ~country,
# y = ~unrecovered,
y = ~ confirmed,
# text = ~ confirmed,
# textposition = 'auto',
type = "bar",
name = "Confermati",
marker = list(color = confirmed_color)
) %>%
plotly::add_trace(
y = ~death,
# text = ~ death,
# textposition = 'auto',
name = "Morti",
marker = list(color = death_color)
) %>%
plotly::layout(
barmode = "stack",
yaxis = list(title = "Casi totali"),
xaxis = list(title = ""),
hovermode = "compare",
margin = list(
# l = 60,
# r = 40,
b = 10,
t = 10,
pad = 2
)
)
```
Mappa dei contagi
=======================================================================
### **Mappa mondiale dei contagi** (*Utilizza le icone + e - per ingrandire o rimpicciolire *)
```{r}
# map tab added by Art Steinmetz
library(leaflet)
library(leafpop)
library(purrr)
cv_data_for_plot <- coronavirus %>%
# dplyr::filter(Country.Region == "Belgium") %>%
dplyr::filter(cases > 0) %>%
dplyr::group_by(Country.Region, Province.State, Lat, Long, type) %>%
dplyr::summarise(cases = sum(cases)) %>%
dplyr::mutate(log_cases = 2 * log(cases)) %>%
dplyr::ungroup()
cv_data_for_plot.split <- cv_data_for_plot %>% split(cv_data_for_plot$type)
pal <- colorFactor(c("orange", "red", "green"), domain = c("confirmed", "death", "recovered"))
map_object <- leaflet() %>% addProviderTiles(providers$Stamen.Toner)
names(cv_data_for_plot.split) %>%
purrr::walk(function(df) {
map_object <<- map_object %>%
addCircleMarkers(
data = cv_data_for_plot.split[[df]],
lng = ~Long, lat = ~Lat,
# label=~as.character(cases),
color = ~ pal(type),
stroke = FALSE,
fillOpacity = 0.8,
radius = ~log_cases,
popup = leafpop::popupTable(cv_data_for_plot.split[[df]],
feature.id = FALSE,
row.numbers = FALSE,
zcol = c("type", "cases", "Country.Region", "Province.State")
),
group = df,
# clusterOptions = markerClusterOptions(removeOutsideVisibleBounds = F),
labelOptions = labelOptions(
noHide = F,
direction = "auto"
)
)
})
map_object %>%
addLayersControl(
overlayGroups = names(cv_data_for_plot.split),
options = layersControlOptions(collapsed = FALSE)
)
```
A riguardo
=======================================================================
```{r}
sprintf("%s - Grafici e dati aggiornati e ricalcolati automaticamente.", date())
```
**Coronavirus Dashboard: il caso in Italia**
Questa Dashboard vuole essere un aiuto alla popolazione Italiana di tenersi aggiornata a riguardo la pandemia mondiale data da COVID-19, causata dal virus SARS-CoV-2 ( 2019 severe acute respiratory syndrome coronavirus 2 ).
Con focus sulla situazione Italiana, in confronto ai paesi Europei che ci stanno vicino, come Germania, Spagna e Francia.
La Dashboard è un estratto del lavoro di Rami Krispin consultabile qui:
[dashboard](https://ramikrispin.github.io/coronavirus_dashboard/){target="_blank"}
e delle sue modifiche apportate da Antoine Soetewey per il Belgio:
[Belgium Dashboard](https://github.com/AntoineSoetewey/coronavirus_dashboard){target="_blank"}
Io ho implementato alcune modifiche necessarie per personalizzare e calcolare i dati per il nostro paese l'Italia.
**Codice**
Questo sito è stato sviluppato in R, un linguaggio di programmazione orientato alla statistica e il framework R Markdown. Il codice di questa Dashboard è disponibile su GitHub [GitHub](https://github.com/akaped/coronavirus_dashboard_italy){target="_blank"} ed è liberamente modificabile.
**Dati**
I dati che vengono utilizzati da questa dashboard fanno parte del pacchetto R sul coronavirus e vengono aggiornati quotidianamente, come anche la dashboard. I dati grezzi sono prelevati dal Johns Hopkins University Center for Systems Science and Engineering (JHU CCSE) Coronavirus [repository](https://github.com/RamiKrispin/coronavirus-csv).
**Sul Autore**
Mi chiamo Pietro Boccaletto, sono un Biologo che si occupa di Bioinformatica nel campo degli RNA non codificanti. Sviluppo e mantengo tools e database che sono d'aiuto al avanzamento della ricerca scientifica.
**Contatti**
Per ogni domanda o Feedback, potete contattarmi a questo indirizzo email: